﻿using FFmpegWinui3.MediaFolder;
using FFmpegWinui3.UlitFolder;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace FFmpegWinui3.Views
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MediaPage : Page
    {
        CanvasBitmap bitmap;

        public MediaPage()
        {
            this.InitializeComponent();
            Init();
        }




        void Init()
        {

            PlayOperate();
            UpdateUi();
        }


        void PlayOperate()
        {
            //播放或粘贴
            play.Click += (s, e) =>
            {
                if (!media.Playing)
                    media.SetSource(pathBox.Text);
                else
                    media.Pause();

            };
            //停止
            stop.Click += (s, e) =>
            {

            };




        }
        DispatcherTimer timer = new DispatcherTimer();
        void UpdateUi()
        {
            var ValueChanged = new RangeBaseValueChangedEventHandler((s, e) =>
            {

            });

            bool progress = false;

            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick += (s, e) =>
            {

                progress = false;
                timeLine.Value = media.Position.TotalSeconds;
                progress = true;
            };
            timer.Start();

            timeLine.ValueChanged += (s, e) =>
            {
                if (progress && media != null)
                {
                    var time = (int)e.NewValue;
                    media.Seek(time);
                }
            };
        }
    }
}
